const path = require('path');
// 引入HtmlWebpackPlugin构造函数
const HtmlWebpackPlugin = require('html-webpack-plugin');


module.exports = {
    // 设置当前为开发模式
    mode: "development",
    devtool: 'inline-source-map',
    // 打包入口文件
    entry: {
        index: './src/index.js',
    },
    output: {
        // 输出文件名
        filename: 'script/[name].[contenthash].js',
        // 输出路径文件夹
        path: path.resolve(__dirname, 'dist'),
        // 每次打包前清空包内文件
        clean: true
    },
    // 配置插件
    plugins: [
        new HtmlWebpackPlugin({
            title: 'Caching',
        }),
    ],

    optimization: {
        splitChunks: {
            cacheGroups: {
                vendor: {
                    test: /[\\/]node_modules[\\/]/,
                    name: 'vendors',
                    chunks: "all"
                }
            }
        }
    }
};